﻿using Native.Sdk.Cqp.Enum;
using Native.Sdk.Cqp.Model;
using System.Text;

namespace Native.Sdk.Cqp.EventArgs
{
    /// <summary>
    /// 提供用于描述酷Q私聊消息事件参数的类
    /// <para/>
    /// Type: 21
    /// </summary>
    public sealed class CQPrivateMessageEventArgs : CQEventEventArgs
    {
        #region --属性--
        /// <summary>
        /// 获取当前事件的消息子类型
        /// </summary>
        public CQPrviateMessageType SubType { get; private set; }

        /// <summary>
        /// 获取当前事件的来源QQ
        /// </summary>
        public QQ FromQQ { get; private set; }

        /// <summary>
        /// 获取当前事件的消息内容
        /// </summary>
        public QQMessage Message { get; private set; }
        #endregion

        #region --构造函数--
        /// <summary>
        /// 初始化 <see cref="CQPrivateMessageEventArgs"/> 类的新实例
        /// </summary>
        /// <param name="api">酷Q的接口实例</param>
        /// <param name="log">酷Q的日志实例</param>
        /// <param name="id">事件id</param>
        /// <param name="type">事件类型</param>
        /// <param name="name">事件名称</param>
        /// <param name="function">事件函数名</param>
        /// <param name="priority">事件优先级</param>
        /// <param name="subType">消息子类型</param>
        /// <param name="msgId">消息ID</param>
        /// <param name="fromQQ">来源QQ</param>
        /// <param name="msg">消息内容</param>
        /// <param name="isRegex">是否为正则消息</param>
        public CQPrivateMessageEventArgs(CQApi api, CQLog log, int id, int type, string name, string function, uint priority, int subType, int msgId, long fromQQ, string msg, bool isRegex)
            : base(api, log, id, type, name, function, priority)
        {
            this.SubType = (CQPrviateMessageType)subType;
            this.FromQQ = new QQ(api, fromQQ);
            this.Message = new QQMessage(api, msgId, msg, isRegex);
        }
        #endregion

        #region --公开函数--
        /// <summary>
        /// 返回表示当前对象的字符串
        /// </summary>
        /// <returns>表示当前对象的字符串</returns>
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendLine(string.Format("ID: {0}", this.Id));
            builder.AppendLine(string.Format("类型: {0}({1})", this.Type, (int)this.Type));
            builder.AppendLine(string.Format("名称: {0}", this.Name));
            builder.AppendLine(string.Format("函数: {0}", this.Function));
            builder.AppendLine(string.Format("优先级: {0}", this.Priority));
            builder.AppendLine(string.Format("子类型: {0}({1})", this.SubType, (int)this.SubType));
            builder.AppendLine(string.Format("账号: {0}", this.FromQQ != null ? this.FromQQ.Id.ToString() : string.Empty));
            builder.Append(this.Message != null ? this.Message.ToString() : "消息: ");
            return builder.ToString();
        }
        #endregion
    }
}
